#!/usr/bin/env python2
#
# Copyright ClusterHQ Inc.  See LICENSE file for details.

"""
Run a build step.

Travis calls this during the `script` phase of its build lifecycle.
 * https://docs.travis-ci.com/user/customizing-the-build

Set ``FLOCKER_BUILDER`` environment variable before calling this script.
"""

from os import environ
from subprocess import call


def tox(tox_env):
    return call([
        "tox",
        # XXX This is a hack to work around broken code and tests that rely on
        # dictionary keys and sets having a consistent order, which they don't.
        # See FLOC-4554.
        "--hashseed", "noset",
        "-e", tox_env
    ])


BUILDERS = {
    "test-admin": tox,
    "test-benchmark": tox,
    "test-flocker": tox,
    "lint": tox,
    "docs-lint": tox,
    "docs-spelling": tox,
    "docs-linkcheck": tox,
    "docs-html": tox,
}


def main():
    builder_name = environ["FLOCKER_BUILDER"]
    builder = BUILDERS[builder_name]
    return builder(builder_name)

if __name__ == "__main__":
    raise SystemExit(main())
